package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.DisplayArea;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.util.CacheDataUtil;
import com.kejiguan.ui.util.CommonDate;

import java.util.List;

/**
 * Created by YYY on 16/7/23.
 */
public class NeAdapter extends RecyclerView.Adapter<NeAdapterVH>{

    private Context mContext;
    private String exhibitionName;
    private DisplayArea displayArea;
//    private List<ExhibitionNeItem> presenterItems;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;

    private int color1,color2,color3,color4,color5;

    public NeAdapter(Context mContext,DisplayArea displayArea)
    {
        this.mContext=mContext;
        this.displayArea=displayArea;
        mInflater=LayoutInflater.from(mContext);

        color1=mContext.getResources().getColor(R.color.text_color1);
        color2=mContext.getResources().getColor(R.color.text_color2);
        color3=mContext.getResources().getColor(R.color.text_color3);
        color4=mContext.getResources().getColor(R.color.text_color3);
        color5=mContext.getResources().getColor(R.color.text_color3);

    }

    @Override
    public NeAdapterVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.fragment_ne_list_item_layout,null);
        return new NeAdapterVH(itemView);
    }

    @Override
    public void onBindViewHolder(NeAdapterVH holder, int position) {

        ExhibitionNeItem presenterItem=displayArea.getExhibitionNeItems().get(position);
        holder.displayNameView.setText(presenterItem.getExhibitionName());
        if(CommonDate.STATE_RUNNING.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color2);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg2);
        }else if (CommonDate.STATE_EXCEPTION.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color3);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else if (CommonDate.STATE_OPEN_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color4);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else if (CommonDate.STATE_CLOSE_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color5);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else
        {
            holder.displayNameView.setTextColor(color1);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg1);
        }
        holder.displayNameView.setVisibility(View.VISIBLE);
        if (null!=onClickListener)
        {
            holder.displayNameView.setOnClickListener(onClickListener);
            holder.displayNameView.setTag(R.id.recyclerview_item_position,position);
        }

    }

    @Override
    public int getItemCount() {


        if (null==displayArea||null==displayArea.getExhibitionNeItems())
        {
            return 0;
        }else
        {
            return displayArea.getExhibitionNeItems().size();
        }

    }

    public ExhibitionNeItem getExhibitionByPosition(int position)
    {
        ExhibitionNeItem exhibitionNeItem=null;
        try {
            exhibitionNeItem=displayArea.getExhibitionNeItems().get(position);
        }catch (Exception e)
        {
            Log.e(NeAdapter.class.getSimpleName(),e.toString());
        }

        return exhibitionNeItem;

    }

    public void setPresenterItems(DisplayArea displayArea) {
        this.displayArea = displayArea;
        notifyDataSetChanged();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public DisplayArea getDisplayArea() {
        return displayArea;
    }

}
